from sqlalchemy import (
    Column,
    Index,
    Integer,
    Text,
    Unicode,
    ForeignKey,
    Table,
    Float,
    DateTime
)
from datetime import datetime
from sqlalchemy.orm import relationship

from .meta import Base

order_item = Table('order_item', Base.metadata,
                  Column('order_id',Integer, ForeignKey('orders.id'), primary_key=True),
                  Column('item_id',Integer, ForeignKey('items.id'), primary_key=True)
                  )

class Order(Base):
    __tablename__='orders'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'), nullable=True)
    user = relationship("User", backref='order')

    items = relationship('Item', secondary=order_item)
    add_time=Column(DateTime,nullable=False,default=datetime.now())
    address=Column(Unicode(50),nullable=False)
    telephone=Column(Unicode(20),nullable=False)